package com.kingre.et.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.context.SecurityContextHolder;

import com.kingre.et.model.IP;
import com.kingre.et.model.School;
import com.kingre.et.service.IIPService;
import com.opensymphony.xwork2.ActionSupport;

public class IPManagerAction extends ActionSupport {
    private static final long serialVersionUID = 4009037638544736407L;
    private static final Logger logger = Logger.getLogger(IPManagerAction.class);
    private String roleName;
    @Autowired
    private IIPService ipService;
    private List<IP> ipList = new ArrayList<IP>();
    private List<School> schoolList = new ArrayList<School>();
    
    private String name;
    private Integer schoolId;
    private Integer id;
    private IP ip;
    private Integer addSchoolId;

    public String execute(){
        roleName = SecurityContextHolder.getContext().getAuthentication().getAuthorities()[0].getAuthority();
        schoolList = ipService.findSchool();
        ipList = ipService.find(schoolId, name);
        return SUCCESS;
    }
    public String delete(){
        logger.debug("id =" + id);
        ipService.delete(id);
        return execute();
    }
    public String add(){
        logger.debug("ip =" + ip);
        ipService.add(ip, addSchoolId);
        addFieldError("dd", getText("user.add.ok"));
        return execute();
    }

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public List<IP> getIpList() {
        return ipList;
    }
    public void setIpList(List<IP> ipList) {
        this.ipList = ipList;
    }
    public IP getIp() {
        return ip;
    }
    public void setIp(IP ip) {
        this.ip = ip;
    }
    public Integer getSchoolId() {
        return schoolId;
    }
    public void setSchoolId(Integer schoolId) {
        this.schoolId = schoolId;
    }
    public List<School> getSchoolList() {
        return schoolList;
    }
    public void setSchoolList(List<School> schoolList) {
        this.schoolList = schoolList;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getAddSchoolId() {
        return addSchoolId;
    }
    public void setAddSchoolId(Integer addSchoolId) {
        this.addSchoolId = addSchoolId;
    }
    public String getRoleName() {
        return roleName;
    }
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

}
